﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BGCOP.CAVTOP.BUSINESSLAYER
{
    public class TareasInner
    {
        public TInnerAccion ObtenerUltimaTarea(int CodeInner)
        {
            using (masterDBACEntities db = new masterDBACEntities())
            {
                var query = (from a in db.TInnerAccion
                             where a.CodeInner == CodeInner &&
                                   a.Cumplido == 0
                             orderby a.fecha descending
                             select a).FirstOrDefault();


                return query;
            }
           
        }

        public void AgregarTarea(int CodeInner, string codigoTarea, string codigoBarras)
        {
            using (masterDBACEntities db = new masterDBACEntities())
            {
                TInnerAccion obj = new TInnerAccion()
                                       {
                                           CodeInner = CodeInner,
                                           CodigoAccion = codigoTarea,
                                           Cumplido = 0,
                                           fecha = DateTime.Now,

                                       };
                db.AddToTInnerAccion(obj);
                db.SaveChanges();
            }
        }
        public void CumplirTarea(TInnerAccion tmp)
        {
            using (masterDBACEntities db = new masterDBACEntities())
            {
                var obj = (from a in db.TInnerAccion where a.id == tmp.id select a).FirstOrDefault();
                obj.Cumplido = 1;
                db.SaveChanges();
            }
        }
    }
}
